package com.tianlh.service.impl.redis;

import java.util.List;
import java.util.UUID;

import com.tianlh.redis.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

/**
 * @author 黑子
 * @Date 2017/12/30 13:50
 */
@Service
public class RedisServiceImpl {

    @Autowired
    RedisClient client;

    public String setString(){
        boolean b = client.set("heizi", UUID.randomUUID().toString().replaceAll("-", ""));
        return b ? "SUCCESS" : "FAILED";
    }

    public void test() throws InterruptedException {
        String key = "heizi";
        Jedis jedis = client.getConnection();
        String s = jedis.watch(key);
        redis.clients.jedis.Transaction transaction = jedis.multi();
        transaction.set(key, "我是黑子");
        System.out.println("我要冬眠了");
        Thread.sleep(10000L);
        List<Object> exec = transaction.exec();
        System.out.println(exec);
    }
}
